package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.Banner;
import com.mvp.shq.washer.utils.ImageUtil;

import java.util.List;

/**
 * Created by Administrator on 2017/8/18.
 */

public class MyViewPagerAdapter  extends PagerAdapter{
    private List<Banner> banners;
    private Context context;
    private ImageUtil imageUtil;
    public MyViewPagerAdapter(Context mContext,List<Banner> list){
        context = mContext;
        banners = list;
        imageUtil = new ImageUtil(context);
    }
    @Override
    public int getCount() {
        return banners.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_card_item,container,false);
        ImageView imageView = (ImageView)view.findViewById(R.id.imageView);
        imageUtil.loadUrlImage(banners.get(position).getImgUrl(),imageView);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View)object);
    }
}
